/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.core.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intelligent.ispc.common.dto.AbstractValueObject;
import com.intelligent.ispc.core.entity.Resource;
import org.dozer.Mapping;

import java.util.List;
import java.util.Set;

/**
 * Created by Rovey.Luo on 2015/10/9.
 */
public class RoleDto extends AbstractValueObject {

    private Long id;
    private String name;
    private String description;
    private String enabled;

    @JsonManagedReference
    private List<ResourceDto> resources = null;

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getEnabled() {
        return enabled;
    }

    public void setEnabled(String enabled) {
        this.enabled = enabled;
    }

    public List<ResourceDto> getResources() {
        return resources;
    }

    public void setResources(List<ResourceDto> resources) {
        this.resources = resources;
    }

    @JsonIgnore
    public Set<String> getPermissions() {
        Set<String> resourceSets = Sets.newHashSet();

        List<ResourceDto> sets = this.getResources();
        if (sets != null) {
            for (ResourceDto res : sets) {
                resourceSets.add(res.getCode());
            }
        }
        return resourceSets;
    }
}
